package com.ai.study.dashscope.controller.rag.config;

import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 * @Author chenwei
 * @Date 2025/5/27 21:55
 */
@Configuration
public class PgVectorStoreConfiguration {

    @Bean(name = "pgVectorStore")
    public PgVectorStore pgVectorStore(JdbcTemplate jdbcTemplate,
                                       @Qualifier("dashScopeEmbeddingModel") EmbeddingModel embeddingModel) {
        DriverManagerDataSource dataSource1 = new DriverManagerDataSource();
        dataSource1.setUrl("jdbc:postgresql://192.168.10.102:5433/springAIVector");
        dataSource1.setUsername("postgres");
        dataSource1.setPassword("postgres");
        jdbcTemplate.setDataSource(dataSource1);

        return PgVectorStore.builder(jdbcTemplate ,embeddingModel)
                // .dimensions(1536)
                // .indexType(PgVectorStore.PgIndexType.valueOf("hnsw"))
                .build();
    }
}
